
package JET.Centers;

import JET.Centers.Scripts.MyScript;
import JET.Scene;
import java.util.Collection;
import java.util.Collections;

/**
 *
 * @author raos
 */
public class ControlCenterHelper {
    static final ControlCenter CC = ControlCenter.getInstance();

    /**
     * Searches for scene object whose scripts enter owns specified script.
     *
     * @param script Script object that owning scene we look for.
     * @return Scene object that holds reference (bu ScriptsCenter) to specified script object.
     */
    static public Scene getSceneOwningScript(MyScript script) {
        Collection<Scene> scenesCol = (Collection) Collections.synchronizedCollection(CC.scenes.values());
        synchronized(scenesCol) {
            for(Scene scene : scenesCol)
                if (scene.SC.getScriptIndex(script) != -1)
                    return scene;
        }

        return null;
    }

    /**
     * Clears all scenes cache.
     */
    static public void clearAllScenesCache() {
        Collection<Scene> scenesCol = (Collection) Collections.synchronizedCollection(CC.scenes.values());
        synchronized(scenesCol) {
            for(Scene scene : scenesCol)
                scene.clearCache();
        }
    }
}
